package com.kuizii.base.common.idgenerator;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;


public class NodeDistribute implements InitializingBean {

    public Integer getNodeId() {
        return nodeId;
    }

    public void setNodeId(Integer nodeId) {
        this.nodeId = nodeId;
    }

    Integer nodeId = 0;

    @Override
    public void afterPropertiesSet() {

        //容器化部署时，先判断是否配置环境变量，如没配就根据IP自动添加节点
        String node_id = "NODE_ID";
        if (StringUtils.isNotBlank(System.getenv().getOrDefault(node_id, ""))) {
            nodeId = Integer.parseInt(System.getenv().get(node_id));
        }

        System.out.println("当前节点id为：" + nodeId);
    }
}
